﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.SuperGrid;
using WoSoft.PACS.Data.CheckData;
using WoSoft.PACS.Data.Models;
using WoSoft.PACS.Win.Forms.SubForms;
using WoSoft.PACS.Win.MyToolBars;
using WoSoft.PACS.Win.Properties;

namespace WoSoft.PACS.Win.Forms
{
    public partial class FrmCaptureWorker : FrmBase
    {
        //检查的业务对象
        private CheckApp _checkapp = new CheckApp();

        //当前选择病人的申请ID
        private string appFormID = string.Empty;

        //当前病人检查号
        private string checkNum = string.Empty;

        //当前病人的检查类型
        private string checkType = string.Empty; 

        //当前病人状态
        private string state_ID = string.Empty;

        //当前报告文档状态
        private string state_Report = string.Empty;

        private DateTime _startTime = Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"));
        private DateTime _endTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")).AddDays(1).AddSeconds(-1);
        private string _departmentID;
        private string _patientName;
        private int _hasApp = 1;
        private int _hasBD = 1;
        private int _executeing = 1;
        private int _finish = 1;

        public FrmCaptureWorker()
        { }

        public FrmCaptureWorker(RibbonBar ribar)
            : base(ribar)
        {
            InitializeComponent();
        }

        //加载数据
        private void FrmCaptureWorker_Load(object sender, EventArgs e)
        {
            //注册热键
            this.pacsCamera1.RegHotKey();

            //加载数据
            this.LoadCheckData();

            //加载部门
            this.LoadDepartment(this.cbDepartment);

            this.cbDepartment.SelectedValueChanged += new EventHandler(cbDepartment_SelectedValueChanged);
            this.superGridControl1.KeyDown += new KeyEventHandler(superGridControl1_KeyDown);
            if (Program.CurrentLoginUser != null && !string.IsNullOrEmpty(Program.CurrentLoginUser.DepartmentID))
            {
                this.cbDepartment.SelectedValue = Program.CurrentLoginUser.DepartmentID;
            }

            //设置按钮可用性
            this.EnabledToolbarItem("del_checkapp", false);
            this.EnabledToolbarItem("bd_checkapp", false);

            //加载采集图像事件
            this.pacsCamera1.onCameraing += new MyControls.PACSCamera.CameraingHandler(pacsCamera1_onCameraing);

            //加载图像删除事件
            this.pacsCamera1.onDeleteImg += new MyControls.PACSCamera.DeleteImgHandler(pacsCamera1_onDeleteImg);

            //双击图像
            this.pacsCamera1.onDbClickImage += new MyControls.PACSCamera.ImageDBClickHandler(pacsCamera1_onDbClickImage);
        }

        void superGridControl1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
            { 
                superGridControl1_RowClick(null, null);
            }
        }

        //采集图像事件
        void pacsCamera1_onCameraing(System.Drawing.Bitmap bmp, string fileName)
        {
            var captureImgsPath = Path.Combine(Application.StartupPath, "CaptureImages");
            var currentDay = DateTime.Now.ToString("yyyyMMdd");
            if (!Directory.Exists(captureImgsPath))
            {//路径不存在,创建根目录
                Directory.CreateDirectory(captureImgsPath);
            }

            //检查当前的目录是否存
            var imgSavePath = Path.Combine(captureImgsPath, currentDay);
            if (!Directory.Exists(imgSavePath))
            {
                Directory.CreateDirectory(imgSavePath);
            }

            var jpgfileName = Path.Combine(imgSavePath, fileName + ".jpg");
            if (bmp != null)
            {
                //保存物理文件
                bmp.Save(jpgfileName);
                var dat = ImageToByte(bmp);

                //保存图像(到数据库)
                if (!string.IsNullOrEmpty(this.appFormID))
                    this._checkapp.SaveImage(fileName, this.appFormID, dat);
            }
        }

        //图像删除事件(控件删除触发)
        void pacsCamera1_onDeleteImg(string fileName)
        {
            //数据库删除
            this._checkapp.DeleteImage(fileName);
        }

        //图像双击事件
        void pacsCamera1_onDbClickImage(Image img)
        {
            var frmImageEdit = new FrmImageEdit(img, appFormID);
            frmImageEdit.StartPosition = FormStartPosition.CenterScreen;
            frmImageEdit.ShowDialog(this);
        }

        //关闭窗口时发生
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            //先关闭摄像头
            this.pacsCamera1.CloseCamera();
            base.OnClosing(e);
        }

        #region 工具栏添加
        //返回所有的操作方法
        public override List<OperationModel> Operations()
        {
            List<OperationModel> functionInfos = new List<OperationModel>();

            //申请
            var appButton = new OperationModel()
            {
                ID = "app_checkapp",
                Name = "申请检查",
                Image = global::WoSoft.PACS.Win.Properties.Resources.add2,
                ClickEvent = new EventHandler(AppClick),
            };
            functionInfos.Add(appButton);

            //删除申请
            var delButton = new OperationModel()
            {
                ID = "del_checkapp",
                Name = "删除申请",
                Image = global::WoSoft.PACS.Win.Properties.Resources.delete2,
                ClickEvent = DeleteClick,
                Enabled = false
            };
            functionInfos.Add(delButton);

            //报到
            var baodao = new OperationModel()
            {
                ID = "bd_checkapp",
                Name = "报到",
                Image = global::WoSoft.PACS.Win.Properties.Resources.document_ok,
                ClickEvent = baodaoClick,
                Enabled = false
            };
            functionInfos.Add(baodao);

            //完成
            var finish = new OperationModel()
            {
                ID = "finish_checkapp",
                Name = "完成",
                Image = global::WoSoft.PACS.Win.Properties.Resources.user1_preferences,
                ClickEvent = FinishClick,
                Enabled = false
            };
            functionInfos.Add(finish);

            //回退
            var back = new OperationModel()
            {
                ID = "back_checkapp",
                Name = "回退",
                Image = global::WoSoft.PACS.Win.Properties.Resources.undo,
                ClickEvent = BackClick,
                Enabled = false
            };
            functionInfos.Add(back);

            //阳性
            var positive = new OperationModel()
            {
                ID = "positive_checkapp",
                Name = "阳性",
                Image = global::WoSoft.PACS.Win.Properties.Resources.first_aid,
                ClickEvent = PositiveClick,
                Enabled = false,
            };
            functionInfos.Add(positive);

            //阴性
            var negative = new OperationModel()
            {
                ID = "negative_checkapp",
                Name = "阴性",
                Image = global::WoSoft.PACS.Win.Properties.Resources.navigate_minus,
                ClickEvent = NegativeClick,
                Enabled = false
            };
            functionInfos.Add(negative);

            //书写报告 
            var writerReport = new OperationModel()
            {
                ID = "report_checkapp",
                Name = "书写报告",
                Image = global::WoSoft.PACS.Win.Properties.Resources.document_edit,
                ClickEvent = WriterReportClick,
                Enabled = true,
            };
            functionInfos.Add(writerReport);

            //删除报告 
            var delReport = new OperationModel()
            {
                ID = "delreport_checkapp",
                Name = "删除报告",
                Image = global::WoSoft.PACS.Win.Properties.Resources.document_delete,
                ClickEvent = DelReportClick,
                Enabled = false
            };
            functionInfos.Add(delReport);

            //审核报告 
            var checkReport = new OperationModel()
            {
                ID = "auditreport_checkapp",
                Name = "审核报告",
                Image = global::WoSoft.PACS.Win.Properties.Resources.user1_lock,
                ClickEvent = CheckReportClick,
                Enabled = false
            };
            functionInfos.Add(checkReport);

            //审核取消 
            var uncheckReport = new OperationModel()
            {
                ID = "auditreport_uncheckapp",
                Name = "审核取消",
                Image = global::WoSoft.PACS.Win.Properties.Resources.document_edit,
                ClickEvent = UnCheckReportClick,
                Enabled = false
            };
            functionInfos.Add(uncheckReport);

            //查看报告 
            var viewReport = new OperationModel()
            {
                ID = "viewreport_checkapp",
                Name = "查看报告",
                Image = global::WoSoft.PACS.Win.Properties.Resources.document_info,
                ClickEvent = ViewReportClick,
                Enabled = false
            };
            functionInfos.Add(viewReport);

            //检索 
            var find = new OperationModel()
            {
                ID = Guid.NewGuid().ToString(),
                Name = "检索病人",
                Image = global::WoSoft.PACS.Win.Properties.Resources.find,
                ClickEvent = FindClick
            };
            functionInfos.Add(find);

            //刷新
            var refresh = new OperationModel()
            {
                ID = Guid.NewGuid().ToString(),
                Name = "刷新数据",
                Image = global::WoSoft.PACS.Win.Properties.Resources.refresh,
                ClickEvent = RefreshClick
            };
            functionInfos.Add(refresh);

            //退出工作站 
            var exit = new OperationModel()
            {
                ID = Guid.NewGuid().ToString(),
                Name = "退出工作站",
                Image = global::WoSoft.PACS.Win.Properties.Resources.exit,
                ClickEvent = ExitClick
            };
            functionInfos.Add(exit);

            return functionInfos;
        }

        #endregion

        #region 操作按钮事件
        //申请登记
        private void AppClick(object sender, EventArgs e)
        {
            SubForms.FrmCheckApp appCheckForm = new SubForms.FrmCheckApp();
            appCheckForm.ShowDialog(this);
            this.appFormID = appCheckForm.AppCheckID;

            //重新加载病人
            //LoadCheckData();

            //定位病人
            //PosPatient(appid);

            RefreshClick(sender, e);
        }
        //定位病人
        private void PosPatient(string appid)
        {
            this.superGridControl1.Update();

            Application.DoEvents();

            if (!string.IsNullOrEmpty(appid))
            {
                //定位到新建病人上病人
                foreach (var item in this.superGridControl1.PrimaryGrid.Rows)
                {
                    var gridGroup = item as GridGroup;
                    if (gridGroup != null)
                    {
                        foreach (var row in gridGroup.Rows)
                        {
                            var gridR = row as GridRow;
                            if (gridR != null)
                            {
                                var objID = gridR["gridColID"].Value.ToString();
                                if (objID.ToUpper() == appid.ToUpper())
                                {
                                    this.superGridControl1.PrimaryGrid.ClearSelectedRows();
                                    this.superGridControl1.PrimaryGrid.SetSelectedRows(gridR.GridIndex, 1, true);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
        //删除申请
        private void DeleteClick(object sender, EventArgs e)
        {
            _checkapp.DeleteApply(this.appFormID);

            RefreshClick(sender, e);

            MessageBoxEx.Show("删除申请成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //报到
        private void baodaoClick(object sender, EventArgs e)
        {
            //未选择行
            if (this.superGridControl1.GetSelectedRows().Count == 0)
            {
                MessageBoxEx.Show("请选择一位病人进行报到", "报到", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            var row = this.superGridControl1.GetSelectedRows()[0] as GridRow;
            if (row != null)
            {
                //检查状态
                var text = row["gridColstate"].Value.ToString();
                if (text == "已申请")
                {
                    //ID值
                    var id = row["gridColID"].Value.ToString();
                    var checkappForm = new FrmCheckApp();
                    checkappForm.AppCheckID = id;
                    checkappForm.ShowDialog(this);

                    //重新加载数据
                    //this.LoadCheckData();
                    //定位病人
                    //PosPatient(id);

                    RefreshClick(sender, e);

                    //启用采集按钮
                    this.pacsCamera1.SetState(2);
                }
                else
                {
                    MessageBoxEx.Show("病人不是已申请状态,无法报到检查", "报到", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

        }
        //完成
        private void FinishClick(object sender, EventArgs e)
        {
            _checkapp.Update_State(this.appFormID, 4);

            DialogResult dialogResult = MessageBoxEx.Show("结果是否阳性", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dialogResult == DialogResult.Yes)
                _checkapp.Update_Sfyx(this.appFormID, 1);
            else
                _checkapp.Update_Sfyx(this.appFormID, 0);

            RefreshClick(sender, e);

            MessageBoxEx.Show("完成成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //回退
        private void BackClick(object sender, EventArgs e)
        {
            //var row = this.superGridControl1.PrimaryGrid.GetSelectedRows()[0];
            //GridRow gridRow = row as GridRow;
            //if (gridRow != null)
            //{
            //    MessageBox.Show(gridRow["gridColName"].Value.ToString());
            //}
            int _stateID = 0;//1=已申请/2=已报到/3=报告中/4=已完成
            switch (state_ID)
            {
                case "已申请":
                    _stateID = 0;
                    break;
                case "已报到":
                    _stateID = 1;
                    //删除检查执行记录
                    _checkapp.DeleteCheckJl(this.appFormID);
                    break;
                case "执行中":
                    _stateID = 2;
                    //删除检查报告记录
                    //_checkapp.DeleteCheckJl(this.appFormID);
                    _checkapp.DeleteReport(this.appFormID);
                    break;
                case "已完成":
                    _stateID = 3;
                    break;
                default:
                    break;
            }
            if (_stateID > 0)
                _checkapp.Update_State(this.appFormID, _stateID);

            RefreshClick(sender, e);

            MessageBoxEx.Show("回退成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //阳性
        private void PositiveClick(object sender, EventArgs e)
        {
            _checkapp.Update_Sfyx(this.appFormID, 1);
            RefreshClick(sender, e);
            MessageBoxEx.Show("标识成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //阴性
        private void NegativeClick(object sender, EventArgs e)
        {
            _checkapp.Update_Sfyx(this.appFormID, 0);
            RefreshClick(sender, e);
            MessageBoxEx.Show("标识成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //写报告
        private void WriterReportClick(object sender, EventArgs e)
        {
            if (state_ID == "已报到")//报到状态
                _checkapp.Update_State(this.appFormID, 3);
            this.pacsCamera1.CloseCamera();//关闭摄像头
            this.pacsCamera1.UnRegHotKey();//取消热键
            if (Settings.Default.ReportMode == "Word")
            {
                SubForms.FrmCheckReport report = new SubForms.FrmCheckReport(this.appFormID, this.checkType);
                report.ShowDialog();
            }
            if (Settings.Default.ReportMode == "Rdlc")
            {
                SubForms.FrmCheckReportNew report = new SubForms.FrmCheckReportNew(this.appFormID, this.checkType);
                report.ShowDialog();
            }
            this.pacsCamera1.RegHotKey();//注册热键
            RefreshClick(sender, e);
        }
        //删除报告
        private void DelReportClick(object sender, EventArgs e)
        {
            _checkapp.DeleteReport(this.appFormID);
            _checkapp.Update_State(this.appFormID, 3);//删除报到后到执行状态

            RefreshClick(sender, e);
            MessageBoxEx.Show("删除报告成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //审核报告
        private void CheckReportClick(object sender, EventArgs e)
        {
            _checkapp.UpdateReport(this.appFormID, Program.CurrentLoginUser.Name, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),4);
            RefreshClick(sender, e);
            MessageBoxEx.Show("审核报告成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //审核取消
        private void UnCheckReportClick(object sender, EventArgs e)
        {
            _checkapp.UpdateReport(this.appFormID,null, null,1);
            RefreshClick(sender, e);
            MessageBoxEx.Show("审核取消成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //查看报告
        private void ViewReportClick(object sender, EventArgs e)
        {
            SubForms.FrmReadReport report = new SubForms.FrmReadReport(this.appFormID);
            report.Show();
        }
        //检索
        private void FindClick(object sender, EventArgs e)
        {
            FrmCheckAppSearch search = new FrmCheckAppSearch();
            var r = search.ShowDialog(this);
            if (r == System.Windows.Forms.DialogResult.OK)
            {
                this._startTime = search.StartTime;
                this._endTime = search.EndTime;
                this._departmentID = search.DepartmentID;
                this._patientName = search.PatientName;
                this._hasApp = search.HasApp;
                this._hasBD = search.HasBD;
                this._executeing = search.Executeing;
                this._finish = search.Finish;

                this.tbValue.Text = this._patientName;

                this.LoadCheckData();
            }
        }
        //刷新
        private void RefreshClick(object sender, EventArgs e)
        {
            this.LoadCheckData();

            //定位病人
            this.PosPatient(this.appFormID);

            //刷新按钮
            superGridControl1_RowClick(null, null);
        }
        //退出
        private void ExitClick(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region 数据查询
        //加载数据
        private void LoadCheckData()
        {
            //查询当前ID
            //var rows = this.superGridControl1.GetSelectedRows();
            //if (rows != null && rows.Count > 0)
            //{
            //    var row = rows[0] as GridRow;
            //    if (row != null)
            //    {
            //        this.appFormID = row["gridColID"].Value.ToString();
            //        this.checkNum = row["gridColCheckNum"].Value != null ? row["gridColCheckNum"].Value.ToString() : string.Empty;
            //    }
            //}


            //默认查询时间
            var startTime = _startTime;
            var endTime = _endTime;

            //检查科室获取
            var departmentObj = this.cbDepartment.SelectedValue;
            var departmentID = departmentObj != null ? departmentObj.ToString() : string.Empty;

            var appNum = string.Empty;
            var checkNum = string.Empty;
            var name = string.Empty;

            //获取条件搜索
            var searchType = this.cbSearchType.SelectedIndex;
            switch (searchType)
            {
                case 0:
                    checkNum = this.tbValue.Text.Trim();
                    break;
                case 1:
                    appNum = this.tbValue.Text.Trim();
                    break;
                case 2:
                    name = this.tbValue.Text.Trim();
                    break;
                default:
                    break;
            }

            //检查状态
            var ckeckApp = this.ckApp.Checked ? 1 : 0;
            var checkbd = this.ckBD.Checked ? 2 : 0;
            var ckeckexe = this.ckExe.Checked ? 3 : 0;
            var ckedkFinish = this.ckFinish.Checked ? 4 : 0;

            //执行查询
            var dt = this._checkapp.GetCheckList(departmentID, checkNum, appNum, name, startTime, endTime, ckeckApp, checkbd, ckeckexe, ckedkFinish);
            this.superGridControl1.PrimaryGrid.DataSource = dt;
            this.superGridControl1.PrimaryGrid.GroupByRow.Text = "状态";

            this.superGridControl1.PrimaryGrid.AutoExpandSetGroup = true;
            this.superGridControl1.PrimaryGrid.GridPanel.AddGroup(this.superGridControl1.PrimaryGrid.Columns["gridColstate"]);
        }

        //选择科室后查询
        private void cbDepartment_SelectedValueChanged(object sender, EventArgs e)
        {
            LoadCheckData();
        }

        //改变状态时查询
        private void ckApp_CheckedChanged(object sender, EventArgs e)
        {
            LoadCheckData();
        }

        //输入值查询事件
        private void tbValue_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {//回车触发查询事件
                LoadCheckData();
            }
        }

        //失去焦点时触发
        private void tbValue_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            LoadCheckData();
        }

        #endregion

        //行选择事件
        private void superGridControl1_RowClick(object sender, GridRowClickEventArgs e)
        {
            var rows = this.superGridControl1.PrimaryGrid.GetSelectedRows();
            if (rows == null || rows.Count == 0)
            {
                return;
            }
            var row = rows[0];
            GridRow gridRow = row as GridRow;
            if (gridRow != null)
            {
                this.appFormID = gridRow["gridColID"].Value.ToString();
                this.checkNum = gridRow["gridColCheckNum"].Value != null ? gridRow["gridColCheckNum"].Value.ToString() : string.Empty;
                this.checkType = gridRow["gridColCheckType"].Value != null ? gridRow["gridColCheckType"].Value.ToString() : string.Empty;
                state_Report = gridRow["gridColreportState"].Value.ToString();//报告文档状态
                state_ID = gridRow["gridColstate"].Value.ToString();//状态 1=已申请/2=已报到/3=报告中/4=已完成

                this.pacsCamera1.CloseCamera();//关闭摄像头
                //刷新窗体按钮
                switch (state_ID)
                {
                    case "已申请":
                        SetAppButton();
                        this.pacsCamera1.SetState(1);
                        break;
                    case "已报到":
                        SetBDButton();
                        this.pacsCamera1.SetState(2);
                        this.pacsCamera1.Play();//自动预览摄像头
                        break;
                    case "执行中":
                        SetZXButton();
                        this.pacsCamera1.SetState(3);
                        this.pacsCamera1.Play();//自动预览摄像头
                        break;
                    case "已完成":
                        SetWCButton();
                        this.pacsCamera1.SetState(4);
                        break;
                    default:
                        break;
                }

                //加载病人信息
                LoadPatientInfos(gridRow);
            }
        }

        //加载病人信息
        private void LoadPatientInfos(GridRow gridRow)
        {
            //加载病人检查信息
            var text1 = "申请单号：{0}     姓名：{1}    年龄：{2}岁   来源科室：{3}   申请医生：{4}  申请时间：{5}";
            var text2 = "检查项目：{0}     临床诊断：{1}         检查目的：{2}";

            //费用性质
            var feeprop = gridRow["gridColProp"].Value.ToString();
            this.tbFee.Text = feeprop;

            var appNum = gridRow["gridColCheckAppNum"].Value.ToString();        //申请单号
            var name = gridRow["gridColName"].Value.ToString();
            var age = gridRow["gridColAge"].Value.ToString();
            var fromDepartment = gridRow["gridColDepartment"].Value.ToString(); //来源科室
            var appdoc = gridRow["gridColAppDoctor"].Value.ToString();          //申请医生
            var apptime = gridRow["gridColAppTime"].Value.ToString();           //申请时间

            text1 = string.Format(text1, appNum, name, age, fromDepartment, appdoc, apptime);
            this.lblInfo1.Text = text1;

            var appItems = gridRow["gridColItemNames"].Value.ToString();           //申请项目
            var diagnosis = gridRow["gridColDiagnosis"].Value.ToString();           //临床诊断
            var checkAim = gridRow["gridColCheckAim"].Value.ToString();             //检查目的
            text2 = string.Format(text2, appItems, diagnosis, checkAim);

            this.lblInfo2.Text = text2;
            //加载图像信息
            this.pacsCamera1.CleraImages();
            var imgList = this._checkapp.GetImage(this.appFormID);
            if (imgList != null && imgList.Count > 0)
            {
                foreach (var imgModel in imgList)
                {
                    if (imgModel.ImageBytes != null)
                    {
                        var bmp = ByteToImage(imgModel.ImageBytes);
                        this.pacsCamera1.AddImage(bmp, imgModel.ID);
                    }
                }
            }
        }

        //完成状态设置
        private void SetWCButton()
        {
            this.EnabledToolbarItem("del_checkapp", false);
            this.EnabledToolbarItem("bd_checkapp", false);
            this.EnabledToolbarItem("finish_checkapp", false);
            //this.EnabledToolbarItem("back_checkapp", true);
            //this.EnabledToolbarItem("positive_checkapp", true);
            //this.EnabledToolbarItem("negative_checkapp", true);
            this.EnabledToolbarItem("report_checkapp", false);
            //this.EnabledToolbarItem("delreport_checkapp", true);
            //this.EnabledToolbarItem("auditreport_checkapp", true);
            //this.EnabledToolbarItem("auditreport_uncheckapp", true);
            this.EnabledToolbarItem("viewreport_checkapp", true);

            if (state_Report == "已审核")
            {
                this.EnabledToolbarItem("back_checkapp", false);
                this.EnabledToolbarItem("positive_checkapp", false);
                this.EnabledToolbarItem("negative_checkapp", false);
                this.EnabledToolbarItem("delreport_checkapp", false);
                this.EnabledToolbarItem("auditreport_checkapp", false);
                this.EnabledToolbarItem("auditreport_uncheckapp", true);
            }
            else
            {
                this.EnabledToolbarItem("back_checkapp", true);
                this.EnabledToolbarItem("positive_checkapp", true);
                this.EnabledToolbarItem("negative_checkapp", true);
                this.EnabledToolbarItem("delreport_checkapp", true);
                this.EnabledToolbarItem("auditreport_checkapp", true);
                this.EnabledToolbarItem("auditreport_uncheckapp", false);
            }
        }

        //执行状态设置
        private void SetZXButton()
        {
            this.EnabledToolbarItem("del_checkapp", false);
            this.EnabledToolbarItem("bd_checkapp", false);
            this.EnabledToolbarItem("finish_checkapp", true);
            this.EnabledToolbarItem("back_checkapp", true);
            this.EnabledToolbarItem("positive_checkapp", false);
            this.EnabledToolbarItem("negative_checkapp", false);
            this.EnabledToolbarItem("report_checkapp", true);
            this.EnabledToolbarItem("delreport_checkapp", false);
            this.EnabledToolbarItem("auditreport_checkapp", false);
            this.EnabledToolbarItem("auditreport_uncheckapp", false);
            this.EnabledToolbarItem("viewreport_checkapp", false);
        }

        //报到状态设置
        private void SetBDButton()
        {
            this.EnabledToolbarItem("del_checkapp", false);
            this.EnabledToolbarItem("bd_checkapp", false);
            this.EnabledToolbarItem("finish_checkapp", false);
            this.EnabledToolbarItem("back_checkapp", true);
            this.EnabledToolbarItem("positive_checkapp", false);
            this.EnabledToolbarItem("negative_checkapp", false);
            this.EnabledToolbarItem("report_checkapp", true);
            this.EnabledToolbarItem("delreport_checkapp", false);
            this.EnabledToolbarItem("auditreport_checkapp", false);
            this.EnabledToolbarItem("auditreport_uncheckapp", false);
            this.EnabledToolbarItem("viewreport_checkapp", false);
        }

        //设置已申请状态
        private void SetAppButton()
        {
            this.EnabledToolbarItem("del_checkapp", true);
            this.EnabledToolbarItem("bd_checkapp", true);
            this.EnabledToolbarItem("finish_checkapp", false);
            this.EnabledToolbarItem("back_checkapp", false);
            this.EnabledToolbarItem("positive_checkapp", false);
            this.EnabledToolbarItem("negative_checkapp", false);
            this.EnabledToolbarItem("report_checkapp", false);
            this.EnabledToolbarItem("delreport_checkapp", false);
            this.EnabledToolbarItem("auditreport_checkapp", false);
            this.EnabledToolbarItem("auditreport_uncheckapp", false);
            this.EnabledToolbarItem("viewreport_checkapp", false);
        }

        private void FrmCaptureWorker_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.pacsCamera1.CloseCamera();//关闭摄像头
            this.pacsCamera1.UnRegHotKey();//取消热键
        }
    }
}
